/*
 * This file Copyright (c) 2015. Walle.
 * (http://www.wallellen.com). All rights reserved.
 *
 *
 * This file is dual-licensed under both the
 * Walle Agreement (WA) and the GNU General Public License.
 * You may elect to use one or the other of these licenses.
 *
 * This file is distributed in the hope that it will be
 * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
 * Redistribution, except as permitted by whichever of the GPL
 * or WA you select, is prohibited.
 *
 * 1. For the GPL license (GPL), you can redistribute and/or
 * modify this file under the terms of the GNU General
 * Public License, Version 3, as published by the Free Software
 * Foundation.  You should have received a copy of the GNU
 * General Public License, Version 3 along with this program;
 * if not, write to the Free Software Foundation, Inc., 51
 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * 2. For the Walle Agreement (WA), this file
 * and the accompanying materials are made available under the
 * terms of the WA which accompanies this distribution, and
 * is available at http://www.wallellen.com/agreement.html
 *
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
 */

package com.wallellen.parameter.service.impl;

import com.wallellen.core.auth.domain.LoginUser;
import com.wallellen.core.time.TimeTool;
import com.wallellen.parameter.dao.AloneApplogDaoInter;
import com.wallellen.parameter.domain.AloneApplog;
import com.wallellen.parameter.service.AloneApplogServiceInter;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;

/**
 * Created by walle on 12/12/15.
 */

@Service
public class AloneApplogServiceImpl
        implements AloneApplogServiceInter {

    @Resource
    private AloneApplogDaoInter aloneApplogDao;

    public AloneApplog insertEntity(AloneApplog entity, LoginUser user) {
        return this.aloneApplogDao.insertEntity(entity);
    }

    public AloneApplog editEntity(AloneApplog entity, LoginUser user) {
        AloneApplog entity2 = this.aloneApplogDao.getEntity(entity.getId());

        entity2.setCtime(entity.getCtime());
        entity2.setDescribes(entity.getDescribes());
        entity2.setAppuser(entity.getAppuser());
        entity2.setLevels(entity.getLevels());
        entity2.setMethod(entity.getMethod());
        entity2.setClassname(entity.getClassname());
        this.aloneApplogDao.editEntity(entity2);
        return entity2;
    }

    public void deleteEntity(String entity, LoginUser user) {
        this.aloneApplogDao.deleteEntity(this.aloneApplogDao.getEntity(entity));
    }

    @Transactional
    public AloneApplog getEntity(String id) {
        if (id == null) {
            return null;
        }
        return this.aloneApplogDao.getEntity(id);
    }

    public AloneApplogDaoInter getaloneApplogDao() {
        return this.aloneApplogDao;
    }

    public void setaloneApplogDao(AloneApplogDaoInter dao) {
        this.aloneApplogDao = dao;
    }

    @Transactional
    public AloneApplog log(String describes, String appuser, String level, String method, String classname, String ip) {
        return this.aloneApplogDao.insertEntity(new AloneApplog(
                TimeTool.getTimeDate14(), describes, appuser, level, method, classname,
                ip));
    }
}